package manager;

import entity.Dish;
import entity.Order;
import entity.Restaurant;
import entity.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderManager {
    private Map<User, List<Order>> userOrders;

    public OrderManager() {
        this.userOrders = new HashMap<>();
    }

    public Order createOrder(User user, Restaurant restaurant, Map<Dish, Integer> items, String address, String phone) {
        Order order = new Order(user, restaurant, items, address, phone);

        // 将订单添加到用户的订单列表中
        userOrders.computeIfAbsent(user, k -> new ArrayList<>()).add(order);

        return order;
    }

    public List<Order> getOrdersByUser(User user) {
        return userOrders.getOrDefault(user, new ArrayList<>());
    }
}